package com.csi.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateStringFormat {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    static {
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    }

    public static String date2String(Date date) {
        return sdf.format(date);
    }

    public static Date string2Date(String str) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            return sdf.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date string2Date1(String dateString) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        try {
            return sdf.parse(dateString);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
